package com.whfc.iot.mach;

import com.whfc.iot.autoconfigure.BrokerProperties;
import com.whfc.iot.server.IotServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.util.ObjectUtils;

/**
 * 机械云管家IOT服务器
 *
 * @author xugcheng
 */
@SpringBootApplication(scanBasePackages = "com.whfc")
@EnableAsync
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class IotMachApplication implements CommandLineRunner {

    public static int DEFAULT_PORT = 8100;

    @Autowired
    private BrokerProperties brokerProperties;

    @Autowired
    private IotServer iotServer;

    public static void main(String[] args) {
        SpringApplication.run(IotMachApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        int port = ObjectUtils.isEmpty(brokerProperties.getPort()) ? DEFAULT_PORT : brokerProperties.getPort();
        iotServer.port(port);
        iotServer.run();
    }
}
